//
//  GoodsInforSysView.m
//  GLGW_Shoping
//
//  Created by yang on 2018/12/6.
//  Copyright © 2018年 yang. All rights reserved.
//

#import "GoodsInforSysView.h"
#import "GoodsNumChangeView.h"

@interface GoodsInforSysView ()
{
    GLGWLabel * sysTitleLabel;
    GLGWButton * bottomBut;
}
@property (nonatomic,strong) GLGWView * bankgroundVoew;
@property (nonatomic,strong) GLGWLabel * stellNameLabel;
@property (nonatomic,strong) GLGWLabel * specAndGoodsNumLabel;
@property (nonatomic,strong) GLGWLabel * warehouseLabel;
@property (nonatomic,strong) GLGWLabel * piceLabel;
@property (nonatomic,strong) GLGWLabel * oldPiceLabel;

@end

@implementation GoodsInforSysView

-(id)initWithGoodsInformationSync{
    if (self = [super initWithFrame:kAppWindow.bounds inSuperView:kAppWindow]) {
        self.backgroundColor = [UIColor colorWithHexString:@"#000000" alpha:0.5];//145
        //
        self.bankgroundVoew = [[GLGWView alloc] initWithInSuperView:self];
        self.bankgroundVoew.backgroundColor = [UIColor whiteColor];
        self.bankgroundVoew.layer.cornerRadius = 12.0;
        self.bankgroundVoew.layer.masksToBounds = YES;
        [self.bankgroundVoew mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self.mas_bottom).offset(-kHeightProportion_In_iPhoneTriploid(300));
            make.left.equalTo(self.mas_left).offset(kWidthProportion_In_iPhoneTriploid(50));
            make.right.equalTo(self.mas_right).offset(-kWidthProportion_In_iPhoneTriploid(50));
        }];
        //
        GLGWView * topView = [[GLGWView alloc] initWithInSuperView:self.bankgroundVoew];
        topView.backgroundColor = [UIColor colorWithHexString:@"#F2F2F2"];
        [topView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.right.equalTo(self.bankgroundVoew);
            make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(46)));
        }];
        //
        sysTitleLabel = [[GLGWLabel alloc] initWithFont:SYSTEMFONT(14) theColor:kColor_Rule_Black inSuperView:topView];
        sysTitleLabel.text = @"同步商品到店铺";
        [sysTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(topView.mas_left).offset(kWidthProportion_In_iPhoneTriploid(15));
            make.top.equalTo(topView.mas_top).offset(kHeightProportion_In_iPhoneTriploid(13));
        }];
        //
        GLGWButton * delegateBut = [[GLGWButton alloc] initInSuperView:topView];
        delegateBut.tag = 200;
        delegateBut.backgroundColor = kRandomColor;
        [delegateBut mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(topView);
            make.right.equalTo(topView.mas_right).offset(-kWidthProportion_In_iPhoneTriploid(5));
            make.width.equalTo(@(kWidthProportion_In_iPhoneTriploid(30)));
            make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(30)));
        }];
        [delegateBut addTarget:self action:@selector(sysAction:) forControlEvents:UIControlEventTouchUpInside];
        //
        self.stellNameLabel = [[GLGWLabel alloc] initWithFont:SYSTEMFONT(14) theColor:kColor_Rule_Black inSuperView:self.bankgroundVoew];
        self.stellNameLabel.numberOfLines = 0;
        self.stellNameLabel.text = @"三级螺纹钢 HRB400E 河钢";
        [self.stellNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.bankgroundVoew.mas_left).offset(kWidthProportion_In_iPhoneTriploid(15));
            make.top.equalTo(topView.mas_bottom).offset(kHeightProportion_In_iPhoneTriploid(12));
            make.right.equalTo(self.bankgroundVoew.mas_right).offset(-kWidthProportion_In_iPhoneTriploid(15));
        }];
        //
        self.specAndGoodsNumLabel = [[GLGWLabel alloc] initWithFont:SYSTEMFONT(12) theColor:[UIColor colorWithHexString:@"#666666"] inSuperView:self.bankgroundVoew];
        self.specAndGoodsNumLabel.text = @"φ6*12  剩余 35 件";
        [self.specAndGoodsNumLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(self.stellNameLabel);
            make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(17)));
            make.top.equalTo(self.stellNameLabel.mas_bottom).offset(kHeightProportion_In_iPhoneTriploid(10));
        }];
        //
        self.warehouseLabel = [[GLGWLabel alloc] initWithFont:SYSTEMFONT(12) theColor:[UIColor colorWithHexString:@"#666666"] inSuperView:self.bankgroundVoew];
        self.warehouseLabel.text = @"北京京南国储库";
        [self.warehouseLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.height.equalTo(self.specAndGoodsNumLabel);
            make.top.equalTo(self.specAndGoodsNumLabel.mas_bottom).offset(kHeightProportion_In_iPhoneTriploid(10));
        }];
        //
        self.piceLabel = [[GLGWLabel alloc] initWithFont:SYSTEMFONT(16) theColor:[UIColor colorWithHexString:@"#EC5353"] inSuperView:self.bankgroundVoew];
        self.piceLabel.text = @"¥3845/吨";
        [self.piceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.warehouseLabel);
            make.top.equalTo(self.warehouseLabel.mas_bottom).offset(kHeightProportion_In_iPhoneTriploid(10));
            make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(22)));
        }];
        //
        self.oldPiceLabel = [[GLGWLabel alloc] initWithFont:SYSTEMFONT(12) theColor:[UIColor colorWithHexString:@"#EC5353"] inSuperView:self.bankgroundVoew];
        NSDictionary *attribtDic = @{NSStrikethroughStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle]};
        NSMutableAttributedString *attribtStr = [[NSMutableAttributedString alloc]initWithString:@"¥3845/吨" attributes:attribtDic];
        self.oldPiceLabel.attributedText = attribtStr;
        [self.oldPiceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.piceLabel.mas_right).offset(kWidthProportion_In_iPhoneTriploid(18));
            make.top.equalTo(self.warehouseLabel.mas_bottom).offset(kHeightProportion_In_iPhoneTriploid(14));
        }];
        //
        GLGWView * lineView = [[GLGWView alloc] initWithInSuperView:self.bankgroundVoew];
        lineView.backgroundColor = [UIColor colorWithHexString:@"#F2F2F2"];
        [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(self.warehouseLabel);
            make.top.equalTo(self.piceLabel.mas_bottom).offset(kHeightProportion_In_iPhoneTriploid(12));
            make.height.equalTo(@1);
        }];
        //
        GLGWLabel * yuanLabel = [[GLGWLabel alloc] initWithFont:SYSTEMFONT(14) theColor:kColor_Rule_Black inSuperView:self.bankgroundVoew];
        yuanLabel.attributedText = [GLGWLabel bllChangeStr:@"加价(元)" changewithStr:@"(元)" changeColoer:kColor_Rule_Black withFont:SYSTEMFONT(10)];
        [yuanLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.warehouseLabel);
            make.top.equalTo(lineView.mas_bottom).offset(kHeightProportion_In_iPhoneTriploid(12));
        }];
        //
        GoodsNumChangeView * goodsNumView = [[GoodsNumChangeView alloc] initWithInSuperView:self.bankgroundVoew];
        [goodsNumView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.bankgroundVoew.mas_right).offset(-kWidthProportion_In_iPhoneTriploid(15));
            make.top.equalTo(lineView.mas_bottom).offset(kHeightProportion_In_iPhoneTriploid(13));
            make.width.width.equalTo(@(kWidthProportion_In_iPhoneTriploid(80)));
            make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(20)));
        }];
        //
        bottomBut = [[GLGWButton alloc] initWithTitle:@"同步到我的店铺" titleLableFont:BOLDSYSTEMFONT(16) titleLableColor:kColor_Rule_Yellow theCornerRadius:0 theBorderWidth:1.0 theBorderColor:[UIColor colorWithHexString:@"#EAEAEA"] backgroundColr:[UIColor whiteColor] inSuperView:self.bankgroundVoew];
        bottomBut.tag = 201;
        [bottomBut mas_makeConstraints:^(MASConstraintMaker *make) {
            make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(50)));
            make.left.right.bottom.equalTo(self.bankgroundVoew);
            make.top.equalTo(yuanLabel.mas_bottom).offset(kHeightProportion_In_iPhoneTriploid(12));
        }];
        [bottomBut addTarget:self action:@selector(sysAction:) forControlEvents:UIControlEventTouchUpInside];
        //
        //增加监听，当键盘出现或改变时收出消息
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
    }
    return self;
}

-(void)sysAction:(GLGWButton *)sender{
    if (sender.tag == 201) {
        if (self.Block_SysncAction) {
            self.Block_SysncAction();
        }
    }
    [self removeFromSuperview];
}

- (void)keyboardWillShow:(NSNotification *)aNotification{
    NSDictionary *userInfo = [aNotification userInfo];
    NSValue *aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
    CGRect keyboardRect = [aValue CGRectValue];
    CGFloat height = keyboardRect.size.height;
    [UIView animateWithDuration:1 animations:^{
        [self.bankgroundVoew mas_updateConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self.mas_bottom).offset(-kHeightProportion_In_iPhoneTriploid(22)-height);
        }];
        [self.bankgroundVoew layoutIfNeeded];//强制绘制
    }];
    
}

- (void)setType:(GoodsInforType)type
{
    _type = type;
    sysTitleLabel.text = @"修改";
    [bottomBut setTitle:@"确认修改" forState:UIControlStateNormal];
}


@end
